//
//  ExpandDynamicCell.m
//  mcrmSAAS
//
//  Created by wjxfhxy on 14-7-10.
//  Copyright (c) 2014年 GuangZhouXuanWu. All rights reserved.
//

#import "ExpandDynamicCell.h"
#import "PositionGroupTableViewCell.h"
#import "TextAreaGroupTableViewCell.h"
#import "MultiSelectGroupTableViewCell.h"
#import "DateTimeGroupTableViewCell.h"
#import "ImagePanelGroupTableViewCell.h"
#import "SwitchSelectGroupTableViewCell.h"
#import "MixedPanelGroupTableViewCell.h"
#import "CreateUUIDGroupTableViewCell.h"

#import "HeadImageView.h"

@interface ExpandDynamicCell ()

@end

@implementation ExpandDynamicCell

@synthesize delegate;

-(id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    
    self.backgroundColor = [UIColor whiteColor];
    
    return self;
}

+(CGFloat)caleHeight
{
    return 40;
}

@end

#pragma mark --
#pragma mark -- headImageGroupTableViewCell

@implementation HeadImageGroupTableViewCell
{
    HeadImageView *_imageView;
    UIImageView *_arrowImageView;
    UILabel *_titlelabel;
}

-(id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    
    _imageView = [[HeadImageView alloc]initWithFrame:CGRectMake(10, 10, 60, 60)];
    _imageView.headImage = [UIImage imageNamed:@"img_defaulthead"];
    [self addSubview:_imageView];
    
    _arrowImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"img_arrow"]];
    [self addSubview:_arrowImageView];
    
    _titlelabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 20)];
    _titlelabel.backgroundColor = [UIColor clearColor];
    _titlelabel.textColor = [UIColor lightGrayColor];
    _titlelabel.font = TextInputCellTextFont;
    _titlelabel.textAlignment = NSTextAlignmentRight;
    _titlelabel.text = @"企业LOGO";
    [self addSubview:_titlelabel];
    
    return self;
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    _imageView.origin = CGPointMake(10, 10);
    _arrowImageView.right = self.width - 10;
    _arrowImageView.centerY = self.height/2;
    _titlelabel.right = _arrowImageView.left -10;
    _titlelabel.centerY = self.height/2;
}

-(void)setHeadImage:(UIImage *)headImage
{
    _imageView.headImage = headImage;
}

-(UIImageView*)headImageView
{
    return _imageView.headImageView;
}

-(void)setTitle:(NSString *)title
{
    _titlelabel.text = title;
}

+(CGFloat)caleHeight
{
    return 80;
}

@end

#pragma mark --
#pragma mark -- textInputGroupTableViewCell

@interface TextInputGroupTableViewCell()<UITextFieldDelegate>
{
    TextInputCellTitleOffsetType _offsetType;
    CGFloat _offsetX;
}

//@property(nonatomic,assign) int keyBoarType;

//@property(nonatomic,assign) int titleAlignment;

@end

@implementation TextInputGroupTableViewCell

-(instancetype)init
{
    return [self initWithFrame:CGRectZero];
}

-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    
    _offsetX = 10;
    
    CGSize size = [@"*" stringSizeWithFont:TextInputCellTextFont];
    
    _maskLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, size.width, 10)];
    _maskLabel.backgroundColor = [UIColor clearColor];
    _maskLabel.textColor = [UIColor redColor];
    _maskLabel.text = @"*";
    _maskLabel.hidden = YES;
    _maskLabel.font = TextInputCellTextFont;
    _maskLabel.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:_maskLabel];
    
    size = [NSString charSizeWithFont:TextInputCellTitleFont];
    _titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, size.width * 6, size.height)];
    _titleLabel.backgroundColor = [UIColor clearColor];
    _titleLabel.textColor = [UIColor blackColor];
    _titleLabel.font = TextInputCellTitleFont;
    _titleLabel.textAlignment = NSTextAlignmentRight;
    [self.contentView addSubview:_titleLabel];
    
    _textField = [[UITextField alloc]initWithFrame:CGRectMake(0, 0, 100, 30)];
    _textField.returnKeyType = UIReturnKeyDone;
    _textField.font = TextInputCellTextFont;
    _textField.clearButtonMode = UITextFieldViewModeWhileEditing;
    _textField.delegate = self;
    
    [self.contentView addSubview:_textField];
    
    return self;
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    
    CGFloat offSetX = _offsetX;
    
    if(_maskLabel != nil)
    {
        _maskLabel.left = offSetX;
        _maskLabel.centerY = 40/2 + 3;
        
        offSetX = _maskLabel.right + 5;
    }
    
    _titleLabel.left = offSetX;
    _titleLabel.centerY = 40/2;
    
    _textField.left = _titleLabel.right + 10;
    _textField.centerY = 40/2;
    _textField.width = self.contentView.width - _textField.left - 10;
}

-(void)setAllowEmpty:(BOOL)allowEmpty
{
    _maskLabel.hidden = allowEmpty;
}

-(BOOL)allowEmpty
{
    return _maskLabel.hidden;
}

-(void)setTitle:(NSString *)title
{
    _titleLabel.text = title;
    _textField.placeholder = [NSString stringWithFormat:@"请输入%@",title];
}

-(NSString*)title
{
    return _titleLabel.text;
}

-(NSString*)text
{
    return _textField.text;
}

-(void)setText:(NSString *)text
{
    _textField.text = text;
}

-(void)setPlaceHolder:(NSString *)placeHolder
{
    _textField.placeholder = placeHolder;
}

-(NSString*)placeHolder
{
    return _textField.placeholder;
}

-(void)setKeyBoarType:(NSInteger)keyBoarType
{
    _textField.keyboardType = keyBoarType;
}

-(void)setTextMaxLength:(NSUInteger)maxLength
{
    _textField.textInputMaxLength = maxLength;
}

-(NSUInteger)textMaxLength
{
    return _textField.textInputMaxLength;
}

-(void)setEditStaticStyle:(BOOL)editStaticStyle
{
    self.userInteractionEnabled = !editStaticStyle;
    if(editStaticStyle == YES)
    {
        _maskLabel.hidden = YES;
        _titleLabel.textColor = [UIColor grayColor];
        _textField.placeholder = @"";
    }
    else
    {
        _maskLabel.hidden = NO;
        _titleLabel.textColor = [UIColor blackColor];
        _textField.placeholder = [NSString stringWithFormat:@"请输入%@",_titleLabel.text];
    }
}

-(void)setTextInputOffsetType:(TextInputCellTitleOffsetType)offsetType
{
    _offsetType = offsetType;
    switch(offsetType)
    {
        case TextInputCellTitleOffsetTypeDefault:
        {
            break;
        }
        case TextInputCellTitleOffsetTypeSixChar:
        {
            [_maskLabel removeFromSuperview];
            _maskLabel = nil;
            CGSize size = [NSString charSizeWithFont:TextInputCellTitleFont];
            _titleLabel.width = size.width * 6;
            break;
        }
        case TextInputCellTitleOffsetTypeFourChar:
        {
            [_maskLabel removeFromSuperview];
            _maskLabel = nil;
            CGSize size = [NSString charSizeWithFont:TextInputCellTitleFont];
            _titleLabel.width = size.width * 4;
            break;
        }
        case TextInputCellTitleOffsetTypeMaskFourChar:
        {
            CGSize size = [NSString charSizeWithFont:TextInputCellTitleFont];
            _titleLabel.width = size.width * 4;
            break;
        }
        case TextInputCellTitleOffsetTypeTwoChar:
        {
            [_maskLabel removeFromSuperview];
            _maskLabel = nil;
            CGSize size = [NSString charSizeWithFont:TextInputCellTitleFont];
            _titleLabel.width = size.width * 2;
            break;
        }
        default:
        {
            [_maskLabel removeFromSuperview];
            _maskLabel = nil;
            break;
        }
    }
    [self setNeedsLayout];
}

-(void)setTextInputOffsetType:(TextInputCellTitleOffsetType)offsetType offSetX:(CGFloat)x
{
    _offsetX = x;
    [self setTextInputOffsetType:offsetType];
}

-(void)setTitleColor:(UIColor *)titleColor
{
    _titleLabel.textColor = titleColor;
}

-(void)setTextColor:(UIColor *)textColor
{
    _textField.textColor = textColor;
}

-(void)textFieldDidBeginEditing:(UITextField *)textField
{
    if([(id<TextInputGroupTableViewCellDelegate>)self.delegate respondsToSelector:@selector(textInputGroupTableViewCell:textFieldDidBeginEditing:)])
        [(id<TextInputGroupTableViewCellDelegate>)self.delegate textInputGroupTableViewCell:self textFieldDidBeginEditing:textField];
}

-(void)textFieldDidEndEditing:(UITextField *)textField
{
    if([(id<TextInputGroupTableViewCellDelegate>)self.delegate respondsToSelector:@selector(textInputGroupTableViewCell:textFieldDidEndEditing:)])
        [(id<TextInputGroupTableViewCellDelegate>)self.delegate textInputGroupTableViewCell:self textFieldDidEndEditing:textField];
}

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    if([(id<TextInputGroupTableViewCellDelegate>)self.delegate respondsToSelector:@selector(textInputGroupTableViewCell:textField:shouldChangeCharactersInRange:replacementString:)])
        return [(id<TextInputGroupTableViewCellDelegate>)self.delegate textInputGroupTableViewCell:self textField:textField shouldChangeCharactersInRange:range replacementString:string];
    return YES;
}

-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    if([(id<TextInputGroupTableViewCellDelegate>)self.delegate respondsToSelector:@selector(textInputGroupTableViewCell:textFieldShouldReturn:)])
        return [(id<TextInputGroupTableViewCellDelegate>)self.delegate textInputGroupTableViewCell:self textFieldShouldReturn:textField];
    return YES;
}

+(CGFloat)caleHeight
{
    return 40;
}

@end


#pragma mark --
#pragma mark -- decimalGroupTableViewCell

@implementation DecimalGroupTableViewCell

-(instancetype)init
{
    self = [super init];
    
    _pointScale = 4;
    
    return self;
}

-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    
    _pointScale = 4;
    
    return self;
}

-(BOOL)textFieldShouldEndEditing:(UITextField *)textField
{
    NSUInteger len = textField.text.length;
    if (len>0)
    {
        NSUInteger dotindex = [textField.text rangeOfString:@"."].location;
        if(dotindex==0)
        {
            NSRange range = {0, 0};
            textField.text = [textField.text stringByReplacingCharactersInRange:range withString:@"0"];
            dotindex=dotindex+1;
            len=len+1;
        }
        if (len==dotindex+1)
    {
            textField.text = [textField.text substringToIndex:dotindex];
        }
        if (dotindex!=NSNotFound) {
            NSInteger integerpart = [[textField.text substringToIndex:dotindex] intValue];
            textField.text = [NSString stringWithFormat:@"%@%@", @(integerpart), [textField.text substringFromIndex:dotindex]];
        }
    }
    return YES;
}

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    if (([textField.text rangeOfString:@"."].location!=NSNotFound) && ([string isEqual:@"."]))
    {
        string = @"";
        return NO;
    }
    NSString * toBeString = [textField.text stringByReplacingCharactersInRange:range withString:string];
    textField.text = toBeString;
    
    NSUInteger len = textField.text.length;
    if (len>0)
    {
        if (len>self.textMaxLength)
        {
            textField.text = [textField.text substringToIndex:self.textMaxLength];
        }
        NSUInteger dotindex = [textField.text rangeOfString:@"."].location;
        if(dotindex == NSNotFound)
        {
            double value = [textField.text doubleValue];
            textField.text = [[NSNumber numberWithDouble:value] stringValue];
            return NO;
        }
        if (len - dotindex > _pointScale + 1)
        {
            double value = [textField.text doubleValue];
            double p = powf(0.1, _pointScale);
            if(value < p)
            {
                textField.text = @"0";
            }
            else
            {
                textField.text = [textField.text substringToIndex:(dotindex + (_pointScale + 1))];
            }
        }
    }
    
    return NO;
}

@end


#pragma mark --
#pragma mark -- DropDownTextGroupTableViewCell
@implementation DropDownTextGroupTableViewCell

-(id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    
    [[self.contentView subviews] enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop)
    {
        if([obj isKindOfClass:[UITextField class]])
        {
            ((UITextField*)obj).enabled = YES;
        }
    }];
    
    return self;
}

-(void)setSelectText:(NSString *)selectText
{
    [super setText:selectText];
    _selectText = selectText;
}

@end


#pragma mark --
#pragma mark -- similarTextInputGroupTableViewCell

@interface SimilarTextInputGroupTableViewCell()
{
    UIActivityIndicatorView *_activityIndicator;
}
@end

@implementation SimilarTextInputGroupTableViewCell

-(id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    
    _activityIndicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
    _activityIndicator.hidden = YES;
    [self.contentView addSubview:_activityIndicator];
    
    return self;
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    
    _activityIndicator.right = self.contentView.width - 10;
    _activityIndicator.centerY = self.contentView.height/2;
    
    if(_activityIndicator.hidden == YES)
        _textField.width = self.contentView.width - _textField.left -10;
    else
        _textField.width = self.contentView.width - _textField.left - _activityIndicator.width - 10 - 10;
}

-(void)hiddenActivityIndicator:(BOOL)hidden
{
    _activityIndicator.hidden = hidden;
    
    [self setNeedsLayout];
}

@end

#pragma mark --
#pragma mark -- similarListGroupTableViewCell

@interface SimilarListGroupTableViewCell ()
{
    UIImageView *_imageView;
    UILabel *_similarLabel;
    
    NSMutableArray *_similarTextLabels;
}
@end

@implementation SimilarListGroupTableViewCell

static CGFloat s_similarListGroupTableViewCellHeifht = 100;

-(id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    
    self.clipsToBounds = YES;
    
    _imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"img_association"]];
    [self.contentView addSubview:_imageView];
    
    CGSize s = [NSString charSizeWithFont:TextInputCellTextFont];
    _similarLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, s.width * 7, s.height)];
    _similarLabel.text = @"系统相似客户有";
    _similarLabel.font = TextInputCellTextFont;
    _similarLabel.textColor = [UIColor colorWithR:17 G:130 B:255 A:1];
    _similarLabel.backgroundColor = [UIColor clearColor];
    [self.contentView addSubview:_similarLabel];
    
    s_similarListGroupTableViewCellHeifht = 0;
    
    return self;
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    
    _imageView.origin = CGPointMake(95, 10);
    _similarLabel.left = _imageView.right + 10;
    _similarLabel.centerY = _imageView.centerY;
    
    CGFloat h = _similarLabel.bottom + 5;
    
    for(UILabel *l in _similarTextLabels)
    {
        l.origin = CGPointMake(_imageView.left, h);
        h += (l.height + 5);
    }
    
    s_similarListGroupTableViewCellHeifht = h;
}

-(void)setSimilarTexts:(NSArray*)similarTexts
{
    if(_similarTextLabels == nil)
        _similarTextLabels = [NSMutableArray new];
    [_similarTextLabels makeObjectsPerformSelector:@selector(removeFromSuperview)];
    [_similarTextLabels removeAllObjects];
    
    s_similarListGroupTableViewCellHeifht = 0;
    
    if(similarTexts.count > 0)
    {
        CGSize s = [NSString charSizeWithFont:TextInputCellTextFont];
        
        for(NSString *t in similarTexts)
        {
            UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, MIN(s.width * t.length,200), s.height)];
            label.text = t;
            label.font = TextInputCellTextFont;
            label.backgroundColor = [UIColor clearColor];
            [self.contentView addSubview:label];
            [_similarTextLabels addObject:label];
        }
      //  [self setNeedsLayout];
        [self layoutSubviews];
    }
}

+(CGFloat)caleHeight
{
    return s_similarListGroupTableViewCellHeifht;
}


@end

#pragma mark --
#pragma mark -- dropDownGroupTableViewCell

@interface DropDownGroupTableViewCell ()<XUIButtonDelegate>
{
}
@end

@implementation DropDownGroupTableViewCell

-(id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    
    _arrowImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"img_arrow_down"]];
    [self.contentView addSubview:_arrowImageView];
    
    _textField.enabled = NO;
    
    _clearBtn = [XUIButton buttonWithStyleType:XUIButtonStyleTypeCenterImage delegate:self];
    [_clearBtn SetImage:[UIImage imageNamed:@"img_grayclear"]];
    _clearBtn.size = CGSizeMake(40, 40);
//    [self addSubview:_clearBtn];
    
    return self;
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    
    _arrowImageView.right = self.contentView.width - 10;
    _arrowImageView.centerY = 40/2;
    
    _clearBtn.center = _arrowImageView.center;
    
    _textField.width = self.contentView.width - _textField.left - _arrowImageView.width - 10 -10;
}

-(void)setTitle:(NSString *)title
{
    _titleLabel.text = title;
    _textField.placeholder = [NSString stringWithFormat:@"请选择%@",title];
}

-(void)setHiddenArrowImage:(BOOL)hiddenArrowImage
{
    if(_clearBtn.superview != nil)
        return;
    
    _arrowImageView.hidden = hiddenArrowImage;
}

-(void)setShowClearButton:(BOOL)showClearButton
{
    if(showClearButton == YES)
    {
        [self.contentView addSubview:_clearBtn];
        [_arrowImageView removeFromSuperview];
    }
    else
    {
        [_clearBtn removeFromSuperview];
        [self.contentView addSubview:_arrowImageView];
    }
}

-(void)setEditStaticStyle:(BOOL)editStaticStyle
{
    super.editStaticStyle = editStaticStyle;
    
    if(editStaticStyle == YES)
        self.hiddenArrowImage = YES;
    else
        self.hiddenArrowImage = NO;
}

-(void)clickedUpInsideOfButton:(XUIButton *)btn
{
    _textField.text = @"";
    self.showClearButton = NO;
    [(id<DropDownGroupTableViewCellDelegate>)self.delegate clickedClearButtonOfDropDownGroupTableViewCell:self];
}

+(CGFloat)caleHeight
{
    return 40;
}

@end

#pragma mark --
#pragma mark -- dateTimeGroupTableViewCell

@implementation DateGroupTableViewCell

@end

#pragma mark --
#pragma mark -- staticTextGroupTableViewCell

@interface StaticTextGroupTableViewCell ()
{
}
@end

@implementation StaticTextGroupTableViewCell

-(id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    
    self.backgroundColor = [UIColor whiteColor];
    
    CGSize size = [NSString charSizeWithFont:TextInputCellTitleFont];
    _titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, size.width * 6, size.height)];
    _titleLabel.backgroundColor = [UIColor clearColor];
    _titleLabel.textColor = [UIColor grayColor];
    _titleLabel.font = TextInputCellTitleFont;
    _titleLabel.textAlignment = NSTextAlignmentRight;
    [self.contentView addSubview:_titleLabel];
    
    _textLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 30)];
    _textLabel.backgroundColor = [UIColor clearColor];
    _textLabel.textColor = [UIColor blackColor];
    _textLabel.font = TextInputCellTextFont;
    _textLabel.textAlignment = NSTextAlignmentLeft;
    _textLabel.lineBreakMode = NSLineBreakByWordWrapping;
    _textLabel.numberOfLines = 0;
    [self.contentView addSubview:_textLabel];
    
    return self;
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    
    _titleLabel.left = 10;
    _titleLabel.centerY = self.contentView.height / 2;
    
    _textLabel.left = _titleLabel.right + 10;
    _textLabel.width = [[self class] textMaxContainWidth:self.width];
    CGFloat h = [_textLabel.text wrapStringSizeWithFont:_textLabel.font forWidth:_textLabel.width].height;
    _textLabel.height = h <= 40 ? 40 : h;
    _textLabel.centerY = self.contentView.height/2;
}

+ (CGFloat)textMaxContainWidth:(CGFloat)containWidth
{
    return containWidth - 10 - [NSString charSizeWithFont:TextInputCellTextFont].width * 6 - 10 - 10;
}

-(void)setTitle:(NSString *)title
{
    _titleLabel.text = title;
}

-(NSString*)text
{
    return _textLabel.text;
}

-(void)setText:(NSString *)text
{
    _textLabel.text = text;
}

//-(void)setTitleAlignment:(NSTextAlignment)titleAlignment
//{
//    _titleLabel.textAlignment = titleAlignment;
//}

+(CGFloat)caleHeight:(NSString*)text forContainWidth:(CGFloat)containWidth
{
    CGFloat w = [[self class] textMaxContainWidth:containWidth];
    
    CGFloat h = [text wrapStringSizeWithFont:TextInputCellTextFont forWidth:w].height;
    
    CGFloat th = [NSString charSizeWithFont:TextInputCellTextFont].height;
    if(h > th)
    {
        if(h >= 40)
            h += 8;
        else
            h = 40 + 8;
    }
    else
        h = 40;
    return h;
}

@end

#pragma mark --
#pragma mark -- activityIndicatorDropDownGroupTableViewCell

@implementation ActivityIndicatorDropDownGroupTableViewCell
{
    UIActivityIndicatorView *_activityIndicator;
}

-(id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    
    _activityIndicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
    _activityIndicator.hidden = YES;
    [self.contentView addSubview:_activityIndicator];
    
    return self;
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    
    _arrowImageView.right = self.contentView.width - 10;
    _arrowImageView.centerY = self.contentView.height/2;
    
    _activityIndicator.right = self.contentView.width - 10;
    _activityIndicator.centerY = self.contentView.height/2;
    
    if(_activityIndicator.hidden == YES)
        _textField.width = self.contentView.width - _textField.left - _arrowImageView.width - 10 -10;
    else
        _textField.width = self.contentView.width - _textField.left - _activityIndicator.width - 10 -10;
}

-(void)setHiddenActivityIndicator:(BOOL)hiddenActivityIndicator
{
    _activityIndicator.hidden = hiddenActivityIndicator;
    
    _arrowImageView.hidden = !hiddenActivityIndicator;
    
    [self layoutIfNeeded];
}

-(BOOL)hiddenActivityIndicator
{
    return _activityIndicator.hidden;
}

@end

@implementation ExpandDynamicCellFactory

+(ExpandDynamicCell*)factory:(FieldDescript *)fixField
{
    ExpandDynamicCell *cell = nil;
    
    switch(fixField.controlType.intValue)
    {
        case DynamicFieldControlTypeText:
        {
            cell = [[TextInputGroupTableViewCell alloc] initWithFrame:CGRectZero];
            [(TextInputGroupTableViewCell*)cell setTitle:fixField.fieldLabel];
            [(TextInputGroupTableViewCell*)cell setAllowEmpty:fixField.isAllowEmpty.intValue];
            [(TextInputGroupTableViewCell*)cell setTextMaxLength:fixField.fieldLength.intValue > 0 ? fixField.fieldLength.intValue : 50];
            break;
        }
        case DynamicFieldControlTypeBigText:
        {
            cell = [[TextAreaGroupTableViewCell alloc] initWithFrame:CGRectZero];
            [(TextAreaGroupTableViewCell*)cell setTitle:fixField.fieldLabel];
            [(TextAreaGroupTableViewCell*)cell setAllowEmpty:fixField.isAllowEmpty.intValue];
            [(TextAreaGroupTableViewCell*)cell setTextMaxLength:fixField.fieldLength.intValue > 0 ? fixField.fieldLength.intValue : 1000];
            break;
        }
        case DynamicFieldControlTypeSingleSelect:
        {
            cell = [[DropDownGroupTableViewCell alloc] initWithFrame:CGRectZero];
            [(DropDownGroupTableViewCell*)cell setTitle:fixField.fieldLabel];
            [(DropDownGroupTableViewCell*)cell setAllowEmpty:fixField.isAllowEmpty.intValue];
            break;
        }
        case DynamicFieldControlTypeMultiSelect:
        {
            cell = [[MultiSelectGroupTableViewCell alloc] initWithFrame:CGRectZero];
            [(MultiSelectGroupTableViewCell*)cell setTitle:fixField.fieldLabel];
            [(MultiSelectGroupTableViewCell*)cell setAllowEmpty:fixField.isAllowEmpty.intValue];
            break;
        }
        case DynamicFieldControlTypeDate:
        case DynamicFieldControlTypeDateTime:
        {
            cell = [[DateGroupTableViewCell alloc] initWithFrame:CGRectZero];
            [(DateGroupTableViewCell*)cell setTitle:fixField.fieldLabel];
            [(DateGroupTableViewCell*)cell setAllowEmpty:fixField.isAllowEmpty.intValue];
            break;
        }
        case DynamicFieldControlTypeDecimal:
        {
            cell = [[DecimalGroupTableViewCell alloc] initWithFrame:CGRectZero];
            [(DecimalGroupTableViewCell*)cell setTitle:fixField.fieldLabel];
            [(DecimalGroupTableViewCell*)cell setAllowEmpty:fixField.isAllowEmpty.intValue];
            [(DecimalGroupTableViewCell*)cell setKeyBoarType:XUINumberKeyboardTypeDecimal];
            [(DecimalGroupTableViewCell*)cell setTextMaxLength:fixField.fieldLength.intValue > 0 ? fixField.fieldLength.intValue : 13];
            break;
        }
        case DynamicFieldControlTypeInt:
        {
            cell = [[TextInputGroupTableViewCell alloc] initWithFrame:CGRectZero];
            [(TextInputGroupTableViewCell*)cell setTitle:fixField.fieldLabel];
            [(TextInputGroupTableViewCell*)cell setAllowEmpty:fixField.isAllowEmpty.intValue];
            [(TextInputGroupTableViewCell*)cell setKeyBoarType:XUINumberKeyboardTypeInteger];
            [(TextInputGroupTableViewCell*)cell setTextMaxLength:fixField.fieldLength.intValue > 0 ? fixField.fieldLength.intValue : 13];
            break;
        }
        case DynamicFieldControlTypePosition:
        {
            cell = [[PositionGroupTableViewCell alloc] initWithFrame:CGRectZero];
            [(PositionGroupTableViewCell*)cell setTitle:fixField.fieldLabel];
            [(PositionGroupTableViewCell*)cell setAllowEmpty:fixField.isAllowEmpty.intValue];
            [(PositionGroupTableViewCell*)cell setTextMaxLength:fixField.fieldLength.intValue];
            break;
        }
        case DynamicFieldControlTypeHeadImage:
        {
            cell = [[HeadImageGroupTableViewCell alloc] initWithFrame:CGRectZero];
            [(HeadImageGroupTableViewCell*)cell setTitle:fixField.fieldLabel];
            break;
        }
        case DynamicFieldControlTypeImagePanel:
        {
            cell = [[ImagePanelGroupTableViewCell alloc] initWithFrame:CGRectZero];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            break;
        }
        case DynamicFieldControlTypeMixedPanel:
        {
            cell = [[MixedPanelGroupTableViewCell alloc] initWithFrame:CGRectZero];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            break;
        }
        case DynamicFieldControlTypeCreateUUID:
        {
            cell = [[CreateUUIDGroupTableViewCell alloc] initWithFrame:CGRectZero];
            NSString *UUID = [XMSGUID GUIDLowString];
            ((CreateUUIDGroupTableViewCell*)cell).createdObj = UUID;
            break;
        }
        case DynamicFieldControlTypeCreateUserID:
        {
            cell = [[CreateUserIdGroupTableViewCell alloc] initWithFrame:CGRectZero];
            ((CreateUserIdGroupTableViewCell*)cell).userId = [[[MyInfo myInfo] userNumber] toNSString];
            break;
        }
        case DynamicFieldControlTypeCreateUserName:
        {
            cell = [[CreateUserNameGroupTableViewCell alloc] initWithFrame:CGRectZero];
            ((CreateUserNameGroupTableViewCell*)cell).userName = [[MyInfo myInfo] userName];
            break;
        }
        case DynamicFieldControlTypeCreateDeptID:
        {
            cell = [[CreateDeptIdGroupTableViewCell alloc] initWithFrame:CGRectZero];
            ((CreateDeptIdGroupTableViewCell*)cell).deptId = [[[MyInfo myInfo] departmentId] toNSString];
            break;
        }
        case DynamicFieldControlTypeCreateDeptName:
        {
            cell = [[CreateDeptNameGroupTableViewCell alloc] initWithFrame:CGRectZero]; 
            ((CreateDeptNameGroupTableViewCell*)cell).deptName = [[MyInfo myInfo] departmentName];
            break;
        }
        case DynamicFieldControlTypeCreateDate:
        {
            cell = [[CreateDateGroupTableViewCell alloc] initWithFrame:CGRectZero];
            ((CreateDateGroupTableViewCell*)cell).currentTime = [NSDate date];
            break;
        }
        case DynamicFieldControlTypeHidden:
        {
            cell = [[TextInputGroupTableViewCell alloc] initWithFrame:CGRectZero];
            break;
        }
        case DynamicFieldControlTypeSingleSelectDic:
        {
            cell = [[DicDropDownGroupTableViewCell alloc] initWithFrame:CGRectZero];
            [(DicDropDownGroupTableViewCell*)cell setTitle:fixField.fieldLabel];
            [(DicDropDownGroupTableViewCell*)cell setAllowEmpty:fixField.isAllowEmpty.intValue];
            break;
        }
            
            
        //static
        case DynamicFieldControlTypeStaticText:
        {
            cell = [[StaticTextGroupTableViewCell alloc] initWithFrame:CGRectZero];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            [(StaticTextGroupTableViewCell*)cell setTitle:fixField.fieldLabel];
            break;
        }
        case DynamicFieldControlTypeTextSingleSelect:
        {
            cell = [[DropDownTextGroupTableViewCell alloc]initWithFrame:CGRectZero];
            ((DropDownTextGroupTableViewCell*)cell).title = fixField.fieldLabel;
            ((DropDownTextGroupTableViewCell*)cell).allowEmpty = fixField.isAllowEmpty.intValue;
            ((DropDownTextGroupTableViewCell*)cell).textMaxLength = fixField.fieldLength.intValue;
            break;
        }
        case DynamicFieldControlTypeMultiSelectStaticText:
        {
            cell = [[MultiSelectStaticTextGroupTableViewCell alloc] initWithFrame:CGRectZero];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            [(MultiSelectStaticTextGroupTableViewCell*)cell setTitle:fixField.fieldLabel];
            break;
        }
        case DynamicFieldControlTypeDateTimeStaticText:
        {
            cell = [[DateTimeStaticTextGroupTableViewCell alloc] initWithFrame:CGRectZero];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            [(DateTimeStaticTextGroupTableViewCell*)cell setTitle:fixField.fieldLabel];
            break;
        }
        case DynamicFieldControlTypePositionStaticText:
        {
            cell = [[PositionStaticTextGroupTableViewCell alloc] initWithFrame:CGRectZero];
            [(PositionStaticTextGroupTableViewCell*)cell setTitle:fixField.fieldLabel];
            break;
        }
        case DynamicFieldControlTypeStaticImagePanel:
        {
            cell = [[ImagePanelStaticGroupTableViewCell alloc] initWithFrame:CGRectZero];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            break;
        }
            
        case DynamicFieldControlTypeSwitchSelect:
        {
            cell = [[SwitchSelectGroupTableViewCell alloc] initWithFrame:CGRectZero];
            [(SwitchSelectGroupTableViewCell*)cell setTitle:fixField.fieldLabel];
            [(SwitchSelectGroupTableViewCell*)cell setAllowEmpty:fixField.isAllowEmpty.intValue];
            break;
        }
        case DynamicFieldControlTypeCreateUUIDStaticText:
        {
            cell = [[CreateUUIDStaticTextGroupTableViewCell alloc] initWithFrame:CGRectZero];
            [(CreateUUIDStaticTextGroupTableViewCell*)cell setTitle:fixField.fieldLabel];
            break;
        }
        case DynamicFieldControlTypeCreateUserIDStaticText:
        {
            cell = [[CreateUserIdStaticTextGroupTableViewCell alloc] initWithFrame:CGRectZero];
            [(CreateUserIdStaticTextGroupTableViewCell*)cell setTitle:fixField.fieldLabel];
            break;
        }
        case DynamicFieldControlTypeCreateUserNameStaticText:
        {
            cell = [[CreateUserNameStaticTextGroupTableViewCell alloc] initWithFrame:CGRectZero];
            [(CreateUserNameStaticTextGroupTableViewCell*)cell setTitle:fixField.fieldLabel];
            break;
        }
        case DynamicFieldControlTypeCreateDeptIDStaticText:
        {
            cell = [[CreateDeptIdStaticTextGroupTableViewCell alloc] initWithFrame:CGRectZero];
            [(CreateDeptIdStaticTextGroupTableViewCell*)cell setTitle:fixField.fieldLabel];
            break;
        }
        case DynamicFieldControlTypeCreateDeptNameStaticText:
        {
            cell = [[CreateDeptNameStaticTextGroupTableViewCell alloc] initWithFrame:CGRectZero];
            [(CreateDeptNameStaticTextGroupTableViewCell*)cell setTitle:fixField.fieldLabel];
            break;
        }
        case DynamicFieldControlTypeCreateDateStaticText:
        {
            cell = [[CreateDateStaticTextGroupTableViewCell alloc] initWithFrame:CGRectZero];
            [(CreateDateStaticTextGroupTableViewCell*)cell setTitle:fixField.fieldLabel];
            break;
        }

        default:
        {
            cell = [[ExpandDynamicCell alloc] initWithFrame:CGRectZero];
            break;
        }
    }
    cell.backgroundColor = [UIColor whiteColor];
    cell.szTag = fixField.fieldName;
    return cell;
}

+(CGFloat)caleHeght:(FieldDescript *)fixField
{
    CGFloat height = 0;
    switch(fixField.controlType.intValue)
    {
        case DynamicFieldControlTypeCreateUUID:
        case DynamicFieldControlTypeCreateUserID:
        case DynamicFieldControlTypeCreateUserName:
        case DynamicFieldControlTypeCreateDeptID:
        case DynamicFieldControlTypeCreateDeptName:
        case DynamicFieldControlTypeCreateDate:
        case DynamicFieldControlTypeHidden:
        {
            height = 0;
            break;
        }
            
        case DynamicFieldControlTypeText:
        case DynamicFieldControlTypeInt:
        case DynamicFieldControlTypeDecimal:
        {
            height = [TextInputGroupTableViewCell caleHeight];
            break;
        }
        case DynamicFieldControlTypeBigText:
        {
            height = [TextAreaGroupTableViewCell caleHeight];
            break;
        }
        case DynamicFieldControlTypeSingleSelect:
        {
            height = [DropDownGroupTableViewCell caleHeight];
            break;
        }
        case DynamicFieldControlTypeMultiSelect:
        {
            height = [DropDownGroupTableViewCell caleHeight];
            break;
        }
        case DynamicFieldControlTypeDate:
        case DynamicFieldControlTypeDateTime:
        {
            height = [DateGroupTableViewCell caleHeight];
            break;
        }
        case DynamicFieldControlTypePosition:
        {
            height = [PositionGroupTableViewCell caleHeight];
            break;
        }
        case DynamicFieldControlTypeHeadImage:
        {
            height = [HeadImageGroupTableViewCell caleHeight];
            break;
        }
        case DynamicFieldControlTypeImagePanel:
        {
            height = [ImagePanelGroupTableViewCell caleHeight];
            break;
        }
        case DynamicFieldControlTypeMixedPanel:
        {
            height = [MixedPanelGroupTableViewCell caleHeight];
            break;
        }
        case DynamicFieldControlTypeSwitchSelect:
        {
            height = [TextInputGroupTableViewCell caleHeight];
            break;
        }
        case DynamicFieldControlTypeSingleSelectDic:
        {
            height = [DicDropDownGroupTableViewCell caleHeight];
            break;
        }
        default:
        {
            height = 40;
            break;
        }
    }
    return height;
}

+(CGFloat)caleStaticText:(DynamicFieldControlType)controlType heightWithText:(NSString*)text forContainWidth:(CGFloat)containWidth
{
    CGFloat height = 40;
    switch(controlType)
    {
        case DynamicFieldControlTypeStaticText:
        {
            height = [StaticTextGroupTableViewCell caleHeight:text forContainWidth:containWidth];
            break;
        }
        case DynamicFieldControlTypeTextSingleSelect:
        {
            height = [DropDownTextGroupTableViewCell caleHeight];
            break;
        }
        case DynamicFieldControlTypeMultiSelectStaticText:
        {
            height = [MultiSelectStaticTextGroupTableViewCell caleHeight:text forContainWidth:containWidth];
            break;
        }
        case DynamicFieldControlTypeDateTimeStaticText:
        {
            height = [DateTimeStaticTextGroupTableViewCell caleHeight:text forContainWidth:containWidth];
            break;
        }
        case DynamicFieldControlTypePositionStaticText:
        {
            height = [PositionStaticTextGroupTableViewCell caleHeight:text forContainWidth:containWidth];
            break;
        }
        case DynamicFieldControlTypeStaticImagePanel:
        {
            height = [ImagePanelStaticGroupTableViewCell caleHeight];
            break;
        }

        default:
        {
            break;
        }
    }
    return height;
}

@end

@implementation DicDropDownGroupTableViewCell

@end

@implementation DicDropDownStaticTextGroupTableViewCell

@end
